package com.hkts.management.unattended.account.service.serviceimpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.unattended.account.entity.HktsUaAccount;
import com.hkts.management.unattended.account.mapper.HktsUaAccountMapper;
import com.hkts.management.unattended.account.service.IHktsUaAccountService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-09-16
 */
@Service
@Transactional
public class HktsUaAccountServiceImpl extends ServiceImpl<HktsUaAccountMapper, HktsUaAccount> implements IHktsUaAccountService {


    @Autowired
    private HktsUaAccountMapper hktsUaAccountMapper;

    @Override
    public IPage<HktsUaAccount> selectPage(Page<HktsUaAccount> page, HktsUaAccount hktsUaAccount) {
        QueryWrapper<HktsUaAccount> query = Wrappers.query();
        QueryWrapper<HktsUaAccount> entityWrapper = getEntityWrapper(query, hktsUaAccount);
        return hktsUaAccountMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsUaAccount> selectList(HktsUaAccount hktsUaAccount) {
        QueryWrapper<HktsUaAccount> query = Wrappers.query();
        QueryWrapper<HktsUaAccount> entityWrapper = getEntityWrapper(query, hktsUaAccount);
        return hktsUaAccountMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsUaAccount> getEntityWrapper(QueryWrapper<HktsUaAccount> entityWrapper, HktsUaAccount hktsUaAccount) {
        //条件拼接
        if (StringUtils.isNotBlank(hktsUaAccount.getcAccName())) {
            entityWrapper.like(HktsUaAccount.C_ACC_NAME, hktsUaAccount.getcAccName());
        }
        if (StringUtils.isNotBlank(hktsUaAccount.getcAccId())) {
            entityWrapper.like(HktsUaAccount.C_ACC_ID, hktsUaAccount.getcAccId());
        }
        return entityWrapper;
    }
}
